Best way to get the Original Target

What's a jQuery like and/or best practices way of getting the original target of an event in jQuery (or in browser javascript in general). I've been using something like this $('body').bind('click', function(e){ //depending on the browser, either srcElement or //originalTarget will be populated with the first //element that intercepted the click before it bubbl

获取原始目标的最佳方法

什么是jQuery和/或最佳实践方式获取jQuery中的事件的原始目标(或通常在浏览器JavaScript中)。 我一直在使用这样的东西 $('body').bind('click', function(e){ //depending on the browser, either srcElement or //originalTarget will be populated with the first //element that intercepted the click before it bubbled up var originalElement = e.srcElement; if(!original

Check if object is a jQuery object

Is there a fast way of checking if an object is a jQuery object or a native JavaScript object? example: var o = {}; var e = $('#element'); function doStuff(o) { if (o.selector) { console.log('object is jQuery'); } } doStuff(o); doStuff(e); obviously, the code above works but it's not safe. You could potentially add a selector key to the o object and get the same result.

检查对象是否是jQuery对象

有没有一种快速的方法来检查一个对象是一个jQuery对象还是一个本地JavaScript对象? 例: var o = {}; var e = $('#element'); function doStuff(o) { if (o.selector) { console.log('object is jQuery'); } } doStuff(o); doStuff(e); 显然,上面的代码工作,但它不安全。 您可以将选择键添加到o对象并获得相同的结果。 有没有更好的方法确保对象实际上是一个jQuery对象? 一些符合(typeof obj == &

Change the selected value of a drop

I have a drop-down list with known values. What I'm trying to do is set the drop down list to a particular value that I know exists using jQuery. Using regular JavaScript, I would do something like: ddl = document.getElementById("ID of element goes here"); ddl.value = 2; // 2 being the value I want to set it too. However, I need to do this with jQuery, because I'm using a CSS class fo

更改放置的选定值

我有一个已知值的下拉列表。 我想要做的是将下拉列表设置为我知道使用jQuery存在的特定值。 使用普通的JavaScript,我会做类似的事情: ddl = document.getElementById("ID of element goes here"); ddl.value = 2; // 2 being the value I want to set it too. 不过,我需要用jQuery来做这件事,因为我为我的选择器使用了CSS类(愚蠢的ASP.NET客户端ID)。 以下是我尝试过的一些事情: $("._statusDDL").val(2); // Doesn

endsWith in JavaScript

How can I check if a string ends with a particular character in JavaScript? Example: I have a string var str = "mystring#"; I want to know if that string is ending with # . How can I check it? Is there a endsWith() method in JavaScript? One solution I have is take the length of the string and get the last character and check it. Is this the best way or there is any other way? UPDATE

endsWith在JavaScript中

如何检查一个字符串是否以JavaScript中的特定字符结尾? 例如:我有一个字符串 var str = "mystring#"; 我想知道该字符串是否以#结尾。 我如何检查它? JavaScript中是否有endsWith()方法? 我有一个解决方案是取出字符串的长度并获取最后一个字符并检查它。 这是最好的方式还是有其他方式? 更新(2015年11月24日): 这个答案最初发布于2010年(前六年),因此请注意以下这些富有洞察力的评论: Shauna - G

how to determine if a dom element is "hidden"?

This question already has an answer here: How do I check if an element is hidden in jQuery? 53 answers 我相信jQuery使用这个逻辑: $(element).is(":visible")

如何确定一个DOM元素是否“隐藏”?

这个问题在这里已经有了答案: 我如何检查一个元素是否隐藏在jQuery中? 53个答案 我相信jQuery使用这个逻辑: $(element).is(":visible")

Get div attribute value on page load

This question already has an answer here: How do I check if an element is hidden in jQuery? 53 answers 做这个: <script> $(document).ready(function(){ var x =$("#divId").css("display"); alert(x); }); </script>

在页面加载时获取div属性值

这个问题在这里已经有了答案: 我如何检查一个元素是否隐藏在jQuery中? 53个答案 做这个: <script> $(document).ready(function(){ var x =$("#divId").css("display"); alert(x); }); </script>

jquery check the attribute element value

This question already has an answer here: How do I check if an element is hidden in jQuery? 53 answers The issue you have is that you're mixing jQuery and vanilla JS methods here, with .attr().display . You're also trying to compare the whole style string against (if it worked) one CSS rule. A better method of achieving this would be to use jQuery's is() method, along with the

jquery检查属性元素值

这个问题在这里已经有了答案: 我如何检查一个元素是否隐藏在jQuery中? 53个答案 你遇到的问题是你在这里使用.attr().display来混合jQuery和vanilla JS方法。 你也试图将整个style字符串与(如果有效的话)一个CSS规则进行比较。 实现这一点的更好方法是使用jQuery的is()方法,以及:visible选择器。 尝试这个: if ($(this).closest('li').is(':visible')) { // script } 如果只想检查元素是否隐藏,可以使用css(

how to check if one element is hidden with jquery

This question already has an answer here: How do I check if an element is hidden in jQuery? 53 answers hidden is not a property of a jQuery object. Try is(':hidden') $('#Div1').click(function () { if ($("#Div2").is(':hidden')) { $("#Div2").show(500); } else { $("#Div2").hide(1000); } }); If the timings were the same you

如何检查一个元素是否隐藏了jquery

这个问题在这里已经有了答案: 我如何检查一个元素是否隐藏在jQuery中? 53个答案 hidden不是jQuery对象的属性。 尝试is(':hidden') $('#Div1').click(function () { if ($("#Div2").is(':hidden')) { $("#Div2").show(500); } else { $("#Div2").hide(1000); } }); 如果时间相同,则可以简单地使用基于当前可见性hide或show的toggle() 。 $('#

do something if element hidden

This question already has an answer here: How do I check if an element is hidden in jQuery? 53 answers try something like this if($('#testElement').is(':visible')){ //what you want to do when is visible } for your code if($('input[name="firstname"], input[name="lastname"]').is(':visible')){ $('input[name="fullname"]').hide(); } REFERENCE http://api.jquery.com/visible-selector/ y

如果元素隐藏,做些事情

这个问题在这里已经有了答案: 我如何检查一个元素是否隐藏在jQuery中? 53个答案 尝试这样的事情 if($('#testElement').is(':visible')){ //what you want to do when is visible } 为你的代码 if($('input[name="firstname"], input[name="lastname"]').is(':visible')){ $('input[name="fullname"]').hide(); } 参考 http://api.jquery.com/visible-selector/ 你应该改变 <input type="text" name="full

JQuery: if div is visible

This question already has an answer here: How do I check if an element is hidden in jQuery? 53 answers You can use .is(':visible') Selects all elements that are visible. For example: if($('#selectDiv').is(':visible')){ Also, you can get the div which is visible by: $('div:visible').callYourFunction(); Live example: console.log($('#selectDiv').is(':visible')); console.log($(

JQuery:如果div可见

这个问题在这里已经有了答案: 我如何检查一个元素是否隐藏在jQuery中? 53个答案 你可以使用.is(':visible') 选择所有可见的元素。 例如: if($('#selectDiv').is(':visible')){ 此外,您可以通过以下方式获取可见的div: $('div:visible').callYourFunction(); 现场示例: console.log($('#selectDiv').is(':visible')); console.log($('#visibleDiv').is(':visible'));#selectDiv { display: none;