[英]Jquery: If statement help, if (radio button is checked) then Jquery, else
I have this JQuery Code, Its in the DOM Ready, on click of .deleteCatFavs it runs this function. 我有这个JQuery代码,它在DOM Ready中,单击.deleteCatFavs时,它将运行此功能。 I want to add some If functionality to this but am having trouble.
我想为此添加一些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);
});
});
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.
我用过一个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';
}
So basically, When the radio button is checked, I want to show the .deleteCatFavs class, otherwise I want it hidden on DOM ready. 所以基本上,当选中单选按钮时,我想显示.deleteCatFavs类,否则我希望将其隐藏在DOM上。 And also, when the .deleteCatFavs is shown and clicked, It must run the above code.
并且,当显示并单击.deleteCatFavs时,它必须运行上面的代码。
Im sure this is so simple, I just dont know how to do isset queries in Javascript. 我确定这是如此简单,我只是不知道如何在Javascript中进行isset查询。
Also, lets keep it simple. 另外,让它保持简单。
How about: 怎么样:
$("input[name='FavCats']").change(function () {
/* Fired immediately after a radio button is clicked with name='FavCats' */
$(".deleteCatFavs").show();
});
Which binds an event handler to the change
event--I'm assuming that if any radio button with name FavCats
is clicked, you want to show .deleteCatFavs
. 它将事件处理程序绑定到
change
事件-我假设如果单击了名称为FavCats
单选按钮, FavCats
显示.deleteCatFavs
。
And: 和:
$(".deleteCatFavs").click(function () {
/* Run jQuery code when element with class deleteCatFavs is clicked */
});
尝试使用最新的jQuery v1.6方法道具
if ( $(elem).prop("checked") )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.