0

How do I send certain buttons to the background and/or disable them depending on what a user chooses? Let's say a user clicks, "iphone 3GS" and all the buttons are enabled and able to be clicked but if, "iphone 4" is chosen then the, "unlocked" button is sent to the background/disabled. If possible, can if statements be used for this function? if ("iphone4") disable ("unlocked, AT&T"), for example. I'm open to jquery but I'm not to familiar so a little detail must be included telling me how to use it.

Here's the jsfiddle: http://jsfiddle.net/nwxLM/

Here's a portion of the script:

if (q1 == "AT&T" && q2 == "8GB" && q3 == "Black" && q4 == "Black") {
            $('#next_button').val('att 8gb black').click(function () {
                window.location.href = 'http://google.com/'
            });

Here's a portion of the HTML:

<div class="radio" id="form">
            <div class="tablebuttons" type="radio" name="q4" value="iPhone-3GS">
                <img width="50px" height="50px" 
src="http://wepriceit.webs.com/Images/iPhone-3GS.png" />
            </div>

The full code is in the jsfiddle located above.

4

1 回答 1

0

我建议你使用一个模板框架,比如 underscorejs 或 mustachejs,当你渲染你的 html 片段时,你可以实现一些条件。

使用 underscore.js 的模板文件示例:

<div class="div-filter">
    <ul class="ul-filter">
        <%var ind =0;
         _.each(types, function(type){ %>
            <li class="li-filter">
                   <img id=<%='img-'+type.name %>
                        notes-id=<%=ind%>
                        class="large-img" 
                        src=<%= 'img/tipo/' + type.name + '.svg' %>  
                        alt=<%="'" + type.name + "'"%> />
            </li>
        <%ind++;
        });%>
    </ul>
</div>

如何使用javascript:

var _tpl = _.template(pTpl);
$(_element).html(_tpl(_typesNotes));

那么什么不是隐含的呢?您需要加载 underscorejs 库,并加载模板文件。

另一种选择,我相信这有效:

$(".elements").on("click",function(){
    $(this).off();
    var elements = $(".elements");
    for (c=0; c < elements.length; c++){
        if($(this).id!==elements.id){
            $(elements).css("display","none");
        }
    }
});
于 2013-09-05T21:32:13.997 回答