简体   繁体   English

jQuery检查元素是否可编辑

[英]jQuery check if element is editable

Problem 问题

I have an editable div containing a few non-editable divs. 我有一个可编辑的div包含一些不可编辑的div。 If a user clicks somewhere I have to find out if he clicked in an area he can actually edit or not. 如果用户点击某个地方,我必须找出他是否点击了他可以实际编辑的区域。

Question

Is there a way to check if an element is editable? 有没有办法检查元素是否可编辑? Something like this: 像这样的东西:

$('my-element-selector').is(':editable')

(And no, the :editable selector is not working, just an example) (不,可编辑的选择器不起作用,只是一个例子)

As far as i heard, there is no such selector called :editable in core jquery, Try to make use of the attribute selector at this context, 据我所知,没有这样的选择器:editable在核心jquery中:editable ,尝试在此上下文中使用attribute selector

$('my-element-selector').is('[contenteditable="true"]')

DEMO DEMO

Try this 尝试这个

$( "div" ).click(function() {
if ( $( this ).hasClass( "editable" ) ) {

}
});

OR 要么

if ( $( "#myDiv" ).is( ".editable" ) ) {

}

Give a specific class for editable div and check for class. 为可编辑的div提供特定的类并检查类。 For example : 例如 :

 if ( $( "#DivId").hasClass( "Editable" ) ) {}

Another way : 其他方式 :

if ( $( "#DivId" ).is( ".Editable" ) ) {

   }

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

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