当前的 HTML 片段:
<ul class="ShippingProviderList">
<li>
<label id="shippingMethod_500dae76abe48_0">
<input id="shippingCheck_500dae76abe48" type="radio" value="0" name="selectedShippingMethod[500dae76abe48]" />
<span class="ShipperName">My Own Shipping Account (Please make sure that account number is specified within your account page or item will not ship!)</span>
<em class="ShipperPrice ProductPrice">$0.00</em>
</label>
</li>
<li> 2nd option may or may not be here </li>
</ul>
当前的 Javascript 代码段:
<script>
var radio = document.getElementById('shippingCheck_500d6aa9a300e'),
var input1 = document.getElementById('FormField_25'),
input2 = document.getElementById('FormField_26'),
btn = document.getElementById('ML20').getElementsByTagName('input')[0];
btn.onclick = function(e) {
if( radio.checked && input1.value.length >= 20 && input2.value.length >= 20 ) {
alert('Please provide a Shipping Account Number in either the Billing or Shipping sections in order to use your own Shipping Account.');
e.preventDefault(); // we all stop the submit from happening.
e.stopPropagation();
return false;
}
// otherwise do something or nothing and let the submit happen.
};
</script>
问题是 500d 运输支票是随机生成的,我无法控制。是否可以通过使用包含 My Own Shipping 术语的跨度类“ShipperName”来调整 Javascript 以提取正确的数据,然后在此之前拉出输入字段?或者有没有更好的方法来做到这一点,我错过了?我无法分配 ID、类或以任何方式更改那里生成的实际 html。