一、读取和设置html内部元件的值
HTML:
<input id="_isExistBilling" type="hidden" value="" />
<input id="_paymentOrderId" type="hidden" value="" />
//给客户端赋值
Document.Find("#_isExistBilling").First().SetAttribute("value", ViewData["IsEnable"].ConvertTo<bool>().ToString());
Document.Find("#_paymentOrderId").First().SetAttribute("value", paymentOrderId.ToString());
fp_paymentMethod.Find("#continue_pay").First().SetAttribute("href", Url.Action("Pay", "Payment", new { paymentOrderId = paymentOrderId }));
二、查找HTML内部元素值
HTML:
<div id="fp_paymentMethod" class="Payment_Con_main w678">
<ul class="Payment_Method">
<!--Paypal credit card-->
<li>
<label class="visa00 fleft mr20" for="paymentMethod_paypalguestchekout"></label>
<div class="ws506 ml130">
<label class="f12 c000" for="paymentMethod_paypalguestchekout">
<input id="paymentMethod_paypalguestchekout" name="paymentMethod" type="radio" value="PaypalGuestCheckout" />
<span id="Paypalguestchekout_Title"></span>
</label>
<p class="f11 c666 lh14 m10 pl10">When you click continue, you will be redirected to the Paypal site to pay with your credit card <span class="orange">as a Paypal guest</span>.</p>
<p class="f11 c666 lh14 m10 pl10">Payment Types:</p>
<div class="visaicon"></div>
</div>
<div class="clear"></div>
</li>
<!--Paypal-->
<li>
<label class="paypal00 fleft mr20" for="paymentMethod_paypal"></label>
<div class="fright ws506">
<label class="f12 c000" for="paymentMethod_paypal">
<input id="paymentMethod_paypal" name="paymentMethod" type="radio" value="PaypalCheckout" />
<span id="PaypalCheckout_Title"></span>
</label>
<p id="PaypalCheckout_Description" class="f11 c666 lh14 m10 pl10">
When you click continue, you will be temporarily redirected to the Paypal site to log in and complete your order.
</p>
</div>
<div class="clear"></div>
</li>
<!--GB-->
<li>
<label class="visa00 fleft mr20" for="paymentMethod_gb"></label>
<div class="ws506 ml130">
<label class="f12 c000" for="paymentMethod_gb">
<input id="paymentMethod_gb" name="paymentMethod" type="radio" value="GlobeBill" />
<span id="GlobeBill_Title"></span>
</label>
<p id="GlobeBill_Description" class="f11 c666 lh14 m10 pl10">Payment Types:</p>
<div class="visaicon width112"></div>
</div>
<div class="clear"></div>
</li>
<!--Webmoney-->
<li>
<label class="webmoney00 fleft mr20" for="paymentMethod_webmoney"></label>
<div class="fright ws506">
<label class="f12 c000" for="paymentMethod_webmoney">
<input id="paymentMethod_webmoney" name="paymentMethod" type="radio" value="Webmoney" />
<span id="Webmoney_Title"></span>
</label>
<p id="Webmoney_Description" class="f11 c666 lh14 m10 pl10">WebMoney is available in all countries and supports currencies RUB,USD,EUR.</p>
</div>
<div class="clear"></div>
</li>
</ul>
<div id="paymentMethod_tips" class="hide">Please choose a payment method.</div>
<a id="continue_pay" href="javascript:void(0);" οnclick="_continue(this);" class="conSaveShipAdress fright"></a>
</div>
ashx代码:
--获取html内部元素的值
var fp_paymentMethod = Document.Find("#fp_paymentMethod").First();
fp_paymentMethod.Find("ul li").ToArray().ForAll(li =>
{
string paymentMethodValue = li.Find("input[name=paymentMethod]").First().Attribute("value").AttributeValue;
if (!paymentRequest.CandidatePaymentMethods.IsNullOrEmpty())
{
if (!paymentRequest.CandidatePaymentMethods.Contains(paymentMethodValue, StringComparer.OrdinalIgnoreCase))
{
li.Remove();
return;
}
}
//如果语种是俄罗斯语,去掉WebMoney支付方式
if (paymentRequest.LanguageCode.ToUpper() == "RU" && paymentMethodValue.ToLower() == "webmoney")
{
li.Remove();
return;
}
});