试图弄清楚如何将Jquery .on()方法与具有多个与之关联的事件的特定选择器一起使用.我之前使用过.live()方法,但不太确定如何用.on()完成同样的壮举.请参阅下面的代码:
$("table.planning_grid td").live({
mouseenter:function(){
$(this).parent("tr").find("a.delete").show();
},
mouseleave:function(){
$(this).parent("tr").find("a.delete").hide();
},
click:function(){
//do something else.
}
});
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过调用以下方式分配多个事件:
$("table.planning_grid td").on({
mouseenter:function(){ //see above
},
mouseleave:function(){ //see above
}
click:function(){ //etc
}
});
Run Code Online (Sandbox Code Playgroud)
但我相信正确使用.on()会是这样的:
$("table.planning_grid").on('mouseenter','td',function(){});
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?或者这里的最佳做法是什么?我尝试了下面的代码,但没有骰子.
$("table.planning_grid").on('td',{
mouseenter: function(){ /* event1 */ },
mouseleave: function(){ /* event2 */ },
click: function(){ /* event3 */ }
});
Run Code Online (Sandbox Code Playgroud)
提前致谢!
这个陈述的等价物是什么?
if(cond1 AND cond2 AND cond3 OR cond4 AND cond5 AND cond6)
Run Code Online (Sandbox Code Playgroud)
是吗
if((cond1 AND cond2 AND cond3) OR (cond4 AND cond5 AND cond6))
Run Code Online (Sandbox Code Playgroud)
要么
if(cond1 AND cond2 AND (cond3 OR cond4) AND cond5 AND cond6)
Run Code Online (Sandbox Code Playgroud)
要么
if(((cond1 AND cond2 AND cond3) OR cond4) AND cond5 AND cond6)
Run Code Online (Sandbox Code Playgroud)
等...
这一直是我一直害怕接近的事情,我只围绕括号中的条件( ).如果我的思想得以解决,那就太好了.
是否有可能使JavaScript正则表达式拒绝空匹配?
可以告诉String.split()方法拒绝空值吗?
console.log("abcccab".split("c"));
//result: ["ab", "", "", "ab"]
//desired result: ["ab", "ab"]
Run Code Online (Sandbox Code Playgroud)
-
当我测试这个时,我偶然发现了事故的部分答案:
console.log("abccacaab".split(/c+/));
//returns: ["ab", "a", "aab"]
Run Code Online (Sandbox Code Playgroud)
但是,当比赛开始时会出现问题:
console.log("abccacaab".split(/a+/));
//returns: ["", "bcc", "c", "b"]
// ^^
Run Code Online (Sandbox Code Playgroud)
有一个干净的答案吗?或者我们只需处理它?
以下代码在编译时抛出"不明确的调用匹配":
class ABC{}
class DEF{}
class Program
{
static void Main(string[] args)
{
Debug.WriteLine(func(null));
}
static string func(ABC abc)
{
return "";
}
static string func(DEF def)
{
return "";
}
}
Run Code Online (Sandbox Code Playgroud)
但是下面的代码编译并运行正常:
static void Main(string[] args)
{
Debug.WriteLine(func(null));
}
static string func(int? abc)
{
return "function a";
}
static string func(float? def)
{
return "function b";
}
Run Code Online (Sandbox Code Playgroud)
输出
function a
Run Code Online (Sandbox Code Playgroud)
C#如何知道在第二个例子中选择哪个函数?
我有一个事件处理程序侦听下拉列表中的更改并设置变量的值.我已将变量声明为全局,即在任何函数之外,然后将值设置为更改.但是,一旦它发生了变化,我需要能够在其他函数中获取变量(不在even处理程序中).我如何从事件处理程序中"提取"它?我试图返回但没有运气 - 这是代码:
$(document).on('change', 'select#search_subject', function () {
if ($('#sBar3').show()) {
$('#sBar3').hide();
}
var subject = $('#search_subject>option:selected').text();
var id = $('#search_subject>option:selected').val();
ajaxSubject(subject, '#sBar3');
return subject;
});
console.log(subject);
Run Code Online (Sandbox Code Playgroud)
日志只显示'空字符串',我感到很困惑.如果可能的话,我不想重新编写代码以包含事件处理程序中的所有内容(那里有很多Google Map生成代码,这会让人感到痛苦) - 我只需要将事件处理器中的主题变量取出来有意义 - 谢谢
我想让2个按钮工作.一个应该保存我的本地存储,另一个应该读取我的本地存储.出于某种原因,他们仍然没有工作.我确实有警报工作,但现在这不起作用.为了读取本地存储,我想使用jQuery append()方法.对我所缺少的任何想法.
脚本
$(document).ready(function() {
function saveLocal(){
if (window.localStorage) {
localStorage.setItem("firstname","myfirstname");
localStorage.setItem("lastname","mylastname");
localStorage.setItem("state","mystate");
alert("The data has been saved locally.");
} else {
alert("Your Browser does not support LocalStorage.");
}
}
function readLocal(){
if (window.localStorage) {
var firstname = localStorage.getItem("myfirstname");
var lastname = localStorage.getItem("mylastname");
var coursetitle = localStorage.getItem("mystate");
$("#message").empty().append( firstname + " " + lastname + " " + state );
}else {
alert("Your Browser does not support LocalStorage.");
}
}
}); // end ready
Run Code Online (Sandbox Code Playgroud)
HTML
</div>
</p>
<p>
<div id="main"> …Run Code Online (Sandbox Code Playgroud)