Jquery:如果语句帮助,如果(选中单选按钮)则 Jquery,否则
我有这个 JQuery 代码,它在 DOM Ready 中,单击 .deleteCatFavs 就会运行这个函数。我想为此添加一些 If 功能,但遇到了麻烦。
// Delete a Favorite Category,
$('.deleteCatFavs').live("click", function(){
var actionRequested = "AJAX_delFavCat";
var url = "index.php";
var catId = $("input[name=FavCats]:checked").val();
var rowId = $("input[name=FavCats]:checked").attr("id");
$.post(url, {AJAX_Action: actionRequested, rowId: rowId},
function(data){
$("#favCats").html(data);
});
});
我想要这个做这样的事情。我已经使用 isset() 来显示我想以 PHP 方式执行的操作,我只是不知道如何在 javascript 中执行此操作。
// On DOM Ready, Hide .deleteCatFavs
$('.deleteCatFavs').hide();
// When the input radio button is checked [name=FavCats],
if(isset($("input[name=FavCats]:checked") // <-- if radio button is selected
$(".deleteCatFavs").show(); // Then show the Delete class,
// And if the .deleteCatFavs class is clicked, then run the JQuery code above
if (.deleteCatFavs.isClicked){
Run Jquery Code here';
}
所以基本上,当选中单选按钮时,我想显示 .deleteCatFavs 类,否则我希望它隐藏在 DOM 上。而且,当显示并单击 .deleteCatFavs 时,它必须运行上面的代码。
我确信这很简单,我只是不知道如何在 Javascript 中进行 isset 查询。
另外,让我们保持简单。
I have this JQuery Code, Its in the DOM Ready, on click of .deleteCatFavs it runs this function. I want to add some If functionality to this but am having trouble.
// Delete a Favorite Category,
$('.deleteCatFavs').live("click", function(){
var actionRequested = "AJAX_delFavCat";
var url = "index.php";
var catId = $("input[name=FavCats]:checked").val();
var rowId = $("input[name=FavCats]:checked").attr("id");
$.post(url, {AJAX_Action: actionRequested, rowId: rowId},
function(data){
$("#favCats").html(data);
});
});
I want this to do something like this. I have used a isset() to show what I want to do in a PHP way, I just dont know how to do this in javascript.
// On DOM Ready, Hide .deleteCatFavs
$('.deleteCatFavs').hide();
// When the input radio button is checked [name=FavCats],
if(isset($("input[name=FavCats]:checked") // <-- if radio button is selected
$(".deleteCatFavs").show(); // Then show the Delete class,
// And if the .deleteCatFavs class is clicked, then run the JQuery code above
if (.deleteCatFavs.isClicked){
Run Jquery Code here';
}
So basically, When the radio button is checked, I want to show the .deleteCatFavs class, otherwise I want it hidden on DOM ready. And also, when the .deleteCatFavs is shown and clicked, It must run the above code.
Im sure this is so simple, I just dont know how to do isset queries in Javascript.
Also, lets keep it simple.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:
它将事件处理程序绑定到
change
事件 - 我假设如果单击任何名为FavCats
的单选按钮,您希望显示.deleteCatFavs
。和:
How about:
Which binds an event handler to the
change
event--I'm assuming that if any radio button with nameFavCats
is clicked, you want to show.deleteCatFavs
.And:
尝试使用最新的 jQuery v1.6 方法 prop
try with latest jQuery v1.6 method prop