简体   繁体   English

javascript onselect for p标签

[英]javascript onselect for p tag

We have a p tag in the page, and we will detect selecting this with javascript onselect or something like this, Perhaps this select can be triggered by mouse or keyboard, and also we can not use of onmouseup or onclick ! 我们在页面中有一个p标签,我们将检测使用javascript onselect或类似的东西进行选择,也许可以通过鼠标或键盘触发此选择,并且我们也不能使用onmouseup或onclick!

<p onselect="alert('selected')" >My p text is here ...</p>

onselect work with dropdown and textbox, and do not work with p tag. onselect用于下拉列表和文本框,不适用于p标签。

You could use onclick , if it suits your needs then: 如果需要,可以使用onclick ,然后:


$("body").delegate("p", "click", function(){
  alert('selected');
});

Hope it helps 希望能帮助到你

在Internet Explorer和Webkit中,您可以使用:

somedom.addEventListener('selectstart',callback)

By default a p tatg is not selectable, you can set it selectable with this short code: 默认情况下, p tatg是不可选的,您可以使用以下短代码将其设置为可选:

$('p')
  .attr("tabIndex", 0)
  .css({"-moz-user-select": "none","-webkit-user-select": "none","-khtml-user-select": "none"})
  .attr("unselectable", "on");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM