带有无线电的JavaScript条件字段不起作用

时间:2015-10-30 18:37:33

标签: javascript jquery twitter-bootstrap-3

我正在尝试使用一个小脚本创建一个带有Bootstrap(jQuery)的表单给定条件(在单选按钮上选择),显示一个或其他元素。

它对我不起作用,调试器中没有错误但它执行操作。

我做错了什么?

void TraCIDemo11p::onData(WaveShortMessage* wsm) {
findHost()->getDisplayString().updateWith("r=16,green");
annotations->scheduleErase(1, annotations->drawLine(wsm->getSenderPos(), mobility->getPositionAt(simTime()), "blue"));
power= (DeciderResult80211*)((PhyToMacControlInfo*)wsm->getControlInfo())->getDeciderResult()->getRecvPower_dBm() ;
received_power.record(power);
if (mobility->getRoadId()[0] != ':') traciVehicle->changeRoute(wsm->getWsmData(), 9999);
if (!sentMessage) sendMessage(wsm->getWsmData());

在jquery.js`之后加载脚本:

<div class="form-group">
    <div class="radio">
        <label>
            <input type="radio" name="typeStorage" id="typeStorageRemote" value="typeStorageRemote" checked>
            Recommended option. Backup stored on remote server using rsync + ssh
        </label>
    </div>
    <div class="radio">
        <label>
//On original value was wrong. I (same value on all radio)
            <input type="radio" name="typeStorage" id="typeStorageLocal" value="typeStorageLocal">
            Options not recommended. Backup stored in device mounted locally
        </label>
    </div>
</div>
<!-- All components tabs storage -->
<!-- Option Remote -->
<div class="form-group" id="groupRemote">
    <div class="form-group">
        <label for="storageServer" class="col-sm-2 control-label">Server (Hostname or Ip)</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="storageServer" placeholder="Server">
        </div>
    </div>
    <div class="form-group">
        <label for="storagePort" class="col-sm-2 control-label">Server port</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="storagePort" placeholder="Port">
        </div>
    </div>
</div>
<!-- Option local -->
<div class="form-group hidden" id="groupLocal">
    <label for="storageLocal" class="col-sm-2 control-label">Local path</label>
    <div class="col-sm-10">
        <input type="text" class="form-control" id="storageLocal" placeholder="Local">
    </div>
</div>    

开发网址(停用所有路线)http://dashboard.cprsync.com/settings

2 个答案:

答案 0 :(得分:0)

在网页上使用非唯一id属性是不好的做法。另外,正如 depperm Stefan Dochow 的评论中所提到的,名称变量也应该是唯一的。

答案 1 :(得分:0)

无法为两个单选按钮分配相同的值(用于错误)。一旦每个人都拥有自己的身份和自己的价值,它就能完美运作。

<div class="radio">
    <label>
        <input type="radio" name="typeStorage" id="typeStorageRemote" value="typeStorageRemote" checked>
        Recommended option. Backup stored on remote server using rsync + ssh
    </label>
</div>
<div class="radio">
    <label>
//On original value was wrong. I (same value on all radio)
        <input type="radio" name="typeStorage" id="typeStorageLocal" value="typeStorageLocal">
        Options not recommended. Backup stored in device mounted locally
    </label>
</div>