button实现选中页面div层的内容,宽屏ok,方屏电脑no,怎么搞定呢_html/css_WEB-ITnose
button实现选中页面div层的内容
我要实现的功能是:点击页面button按钮后,实现对某div层里面内容(包括div内的文字和图片,选中这些内容,类似ctrl+a的效果),这个效果目前已经实现了,下面给出了我的代码,但是用笔记本(宽屏)访问的时候是可以达到效果的,用台式机(方屏)却没有这个效果。麻烦哪位高手帮忙看看能否改进一下,不用考虑浏览器的兼容性,适合任一浏览器即可(我常用的是360安全浏览器5.0版本,ie内核的)。
==button按钮=================
<input id="bt_a" type="button" value="选中产品内容" onclick= "rdl_createRange1()"/>
===产品内容所在层代码================
<div id="com_a"><div id="com_b" class="boxCenterList RelaArticle"></div> <div id="com_c"> <blockquote> {$goods.goods_desc} //产品内容包含文字和图片 </blockquote> </div></div>
===实现选中div层内容功能的js================
<script> function rdl_createRange1(){ //这个地方只能选取id为com_b的层,ecshop商城的产品页面var oMessage=document.all("com_b"); var oTextRange=document.body.createTextRange(); with (oTextRange) { moveToElementText(oMessage); execCommand("SelectAll"); } var oTextRange=document.selection.createRange(); } </script>
回复讨论(解决方案)
把
var oMessage=document.all(" com_b");
改成
var oMessage=document.all(" com_c");
关键问题怎么用代码来获取判断是宽屏还是方屏????
把
var oMessage=document.all("com_b");
改成
var oMessage=document.all("com_c");
我不知道是什么原因,使用com_c 是不行的,没有数据的。而且我用谷歌浏览器审查元素的时候,也发现实际的页面还是在com_b里,估计是我少加一个结尾/div了。
现在的问题是宽屏可以,方屏不行。头疼

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...
