我想在组合框中的对象中添加一个新值,而我正在这样做,就像我对其他值所做的那样,我得到一个消息,它是未定义的。任何想法如何解决它?
main.js
$(document).ready(function () {
//the ip-address will have to change to the ip of the host of the app.
//in my case the ip is 192.168.1.68
var conn = new WebSocket('ws://localhost:8080');
var chatForm = $(".chatForm"),
messageInputField = chatForm.find("#message"),
messagesList = $("#container"), //taked the name container to match the name of the css and work with the jquery draggabilly
usernameForm = $(".username-setter"),
usernameInput = usernameForm.find(".username-input"),
comboBox = $(".comboboxvalue"),
category = comboBox.find("#indexNr");
的index.php
<div class="container">
<div class="row">
<div class="col-md-push-2 col-md-8">
<h2>WorkShoppy Messages Application</h2>
<h3>Username: <span class="username label label-primary" ></span></h3>
<div class="row" id="set">
<form class="username-setter" action="index.php" method="post">
<div class="form-group">
<label for="">Set username</label>
<input type="text" name="name" value="" class="form-control username-input" >
</div>
<button class="btn btn-primary pull-right" name="button" id="btn" onclick="myFunction()">Set</button>
</form>
</div>
<label for="indexNr">Category</label>
<br>
<select id="indexNr" id="indexNr" name="indexNr">
<option value="positive" class="comboboxvalue">Positive</option>
<option value="negative" class="comboboxvalue">Negative</option>
</select>
</div>
</div>
</div>
任何想法如何解决这个问题?
答案 0 :(得分:0)
替换这些行
comboBox = $(".comboboxvalue"),
category = comboBox.find("#indexNr");
带
category = $("#indexNr").val()
或
category = $("#indexNr option:selected").val();
还会将其他ID属性移除到select中。