我正在使用一些 javascript 来验证表单。它在 Firefox、IE10 和 Chrome 中运行良好。有没有办法让下面的代码在 Safari 和 IE9 中工作?单击捐赠按钮时,应要求输入学生姓名。但是在 Safari 和 IE9 中,强制字段没有被识别,它只是带你去贝宝。
<script>
function validateForm()
{
var x=document.forms["myForm"]["os0"].value;
if (x==null || x=="")
{
alert("Please Enter the Child Your Sponsoring and Click Donate");
return false;
}
}
</script>
<form name="myForm" action="https://www.paypal.com/cgi-bin/webscr" onsubmit="return validateForm()" method="post">
<input type="hidden" name="on0" value="Child Sponsored Name" />Please enter the student's First and Last Name Your Sponsoring and click Donate
<input type="text" maxlength="200" name="os0" required/><input type="hidden" name="cmd" value="_donations" />
<input type="hidden" name="business" value="email@website.com" /><input type="hidden" name="lc" value="US" />
<input type="hidden" name="item_name" value="5k Run Fundraiser" />
<input type="hidden" name="no_note" value="0" />
<input type="hidden" name="cn" value="ADD DONOR NAME" />
<input type="hidden" name="no_shipping" value="2" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted" />
<input type="image" alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" />
<img alt="" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1" border="0" />
</form>