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

AI Hentai Generator
Generate AI Hentai for free.

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



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

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.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

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.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.
