我有一个drop drown列表,我无法检查是否从下拉列表中选择了一个值
以下是我的HTML代码:
<label class="paylabel" for="cardtype">Card Type:</label>
<select id="cardtype" name="cards">
<option value="selectcard">--- Please select ---</option>
<option value="mastercard">Mastercard</option>
<option value="maestro">Maestro</option>
<option value="solo">Solo (UK only)</option>
<option value="visaelectron">Visa Electron</option>
<option value="visadebit">Visa Debit</option>
</select><br/>
Run Code Online (Sandbox Code Playgroud)
以下是我的JavaScript代码:
var card = document.getElementByName("cards")[0].value;
if (card.value == selectcard) {
alert("Please select a card type");
}
Run Code Online (Sandbox Code Playgroud) 我无法尝试以24小时格式显示时间.我有它在另一个时区显示时间但我不能让它以24小时格式显示.
<TextClock
android:id="@+id/hk_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timeZone="GMT+0800"
android:format24Hour="MMM dd, yyyy k:mm" />
Run Code Online (Sandbox Code Playgroud)
还可以使用TextClock显示日期吗?
我有一个带有按钮的HTML表单,单击该按钮时,它将检查字段是否为空.这是我的代码的一部分,它进行验证(它的工作原理):
var errorMessage ="";
if (document.getElementById('username').value == "")
{
errorMessage += "Please enter a username \n";
document.getElementById('username').style.borderColor = "red";
}
if (document.getElementById('fname').value == "")
{
errorMessage += "Please enter a first name \n";
document.getElementById('fname').style.borderColor = "red";
}
if (document.getElementById('lname').value == "")
{
errorMessage += "Please enter a last name \n";
document.getElementById('lname').style.borderColor = "red";
}
if (errorMessage != "")
{
alert(errorMessage);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是因为我有更多的字段需要验证,我想知道是否有更好的方法来做这个而不是有这么多if语句(我试图尽可能少的代码).我正在考虑使用switch case语句,但这会有用吗?有什么建议?
我有一个用户可以选择项目的网站,然后显示详细信息,包括数量.我还在div中包含了一个按钮,这样当单击时,它应该将数量减少1.
$("#btnBuy1").click(function()
{
if (!sessionStorage['quantity1'])
{
sessionStorage['quantity1']=1;
}
else
{
sessionStorage['quantity1']++;
}
$("#dropbox").html('<div id = "1"><img class = "thumb" id = "t1" src="../images/birthday_metoyou.jpg" />' + teddy[1].desc + ", Price £"
+ teddy[1].price + ", Quantity: " + sessionStorage.getItem('quantity1') + "<button id = 'btnRemove1'>Remove</button></div><br/>");
updateBasket();
sessionStorage["total1"] = parseInt(sessionStorage.getItem('quantity1')) * teddy[1].price;
updateSubtotal();
if (Modernizr.sessionstorage)
{ // check if the browser supports sessionStorage
myids.push(teddy[1].partnum); // add the current username to the myids array
sessionStorage["ids"]=JSON.stringify(myids); // convert it to a string and put into …Run Code Online (Sandbox Code Playgroud) javascript ×3
html ×2
android ×1
click ×1
clock ×1
function ×1
html-select ×1
jquery ×1
time ×1
validation ×1