亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

請問怎么樣才能選中哪個alert哪個呢

現在是不管選中那個 都全部顯示 ?“用鼠標選中文字”,我想 只alert選中的文字

正在回答

1 回答

<!DOCTYPE html>

<html>


<head>

? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

? ? <title></title>

? ? <style>

? ? .left div,

? ? .right div {

? ? ? ? width: 500px;

? ? ? ? height: 80px;

? ? ? ? padding: 5px;

? ? ? ? margin: 5px;

? ? ? ? float: left;

? ? ? ? border: 1px solid #ccc;

? ? }

? ??

? ? .left div {

? ? ? ? background: #bbffaa;

? ? }

? ??

? ? .right div {

? ? ? ? background: yellow;

? ? }

? ??

? ? select {

? ? ? ? height: 100px;

? ? }

? ? </style>

? ? <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>

</head>


<body>

? ? <h2>input與textarea</h2>

? ? <div class="left">

? ? ? ? <h4>測試一</h4>

? ? ? ? <div class="aaron">

? ? ? ? ? ? 選中文字:input

? ? ? ? ? ? <input type="text" value="慕課網" />

? ? ? ? </div>

? ? ? ? <button id="bt1">觸發input元素的select事件</button>

? ? ? ??

? ? ? ? <h4>測試二</h4>

? ? ? ? <div class="aaron">

? ? ? ? ? ? textarea:

? ? ? ? ? ? <textarea rows="3" cols="20">用鼠標選中文字</textarea>

? ? ? ? </div>

? ? </div>

?

? ? <script type="text/javascript">


? ? //監聽input元素中value的選中

? ? //觸發元素的select事件

? ? $("input").select(function(e){

? ? ? ? alert(e.target.value)

? ? ? ? return false

? ? })

? ? $("#bt1").click(function(){

? ? ? ? $("input").select();

? ? })



? ? //監聽textarea元素中value的選中

? ? $('textarea').select(function(e) {

? ? ? ? alert(window.getSelection().toString());//非IE內核瀏覽器可以用這種方法,考慮兼容性的話你可以用getselectionstart()和getselectionend()

? ? });


? ? </script>

</body>


</html>


0 回復 有任何疑惑可以回復我~
#1

第二熱情 提問者

非常感謝!
2016-09-04 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

請問怎么樣才能選中哪個alert哪個呢

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號