Jquery:如果语句帮助,如果(选中单选按钮)则 Jquery,否则

发布于 2024-11-06 06:26:42 字数 1242 浏览 4 评论 0原文

我有这个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情话难免假 2024-11-13 06:26:42

怎么样:

$("input[name='FavCats']").change(function () {
    /* Fired immediately after a radio button is clicked with name='FavCats' */
    $(".deleteCatFavs").show();
});

它将事件处理程序绑定到 change 事件 - 我假设如果单击任何名为 FavCats 的单选按钮,您希望显示 .deleteCatFavs

和:

$(".deleteCatFavs").click(function () {
    /* Run jQuery code when element with class deleteCatFavs is clicked */
});

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.

And:

$(".deleteCatFavs").click(function () {
    /* Run jQuery code when element with class deleteCatFavs is clicked */
});
趁年轻赶紧闹 2024-11-13 06:26:42

尝试使用最新的 jQuery v1.6 方法 prop

if ( $(elem).prop("checked") )

try with latest jQuery v1.6 method prop

if ( $(elem).prop("checked") )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文