我正在尝试使用按钮链接在单击时在表单字段中生成特定代码,但似乎找不到任何有效的解决方案。我知道必须有一个Javacript答案,但没有一个建议的解决方案能够完成它。
表格代码:
<div class="nm-checkout-form-coupon">
<form class="checkout_coupon" method="post" style="display:none">
<p class="form-row">
<input type="text" id="coupon_code" name="coupon_code" class="input-text" placeholder="<?php _e( 'Physician Code', 'woocommerce' ); ?>" id="coupon_code" value="" required />
</p>
<p class="for-row">
<p>Don't have a Physician Code? <a href="" data-toggle="modal" data-target="#physcode">Get one here!</a></p>
<!-- Physician Code Modal -->
<div class="modal fade access-code-popup" id="physcode" tabindex="-1" role="dialog" aria-labelledby="physcodelabel" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<p>AQ Skin Pro products are available exclusively through participating clinics and physicians offices. If you do not have an Exclusive Physician Code, click "generate a code" below.</p>
<button class="nm-simple-add-to-cart-button single_add_to_cart_button button alt" data-dismiss="modal" aria-label="Close" onClick="fillFields('coupon_code')" alutocomplete="off">Generate a Code</button>
</div>
</div>
</div>
</div>
</p>
<p class="form-row">
<input type="submit" class="button" name="apply_coupon" value="<?php _e( 'Apply Physician Code', 'woocommerce' ); ?>" />
</p>
</form>
</div>
答案 0 :(得分:0)
您目前的尝试并不遥远:public void swap (String [] array, int i, int j) {
String tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
public static int partition (String [] array, int low, int high) {
String pivot = array[low];
int index = low+1;
for (int i = low+1; i <= high; i++) {
if (pivot.compareTo(array[i]) > 0) {
swap(array, i, index);
index++;
}
}
swap(array, low, index-1);
return index-1;
}
public static void qsort(String [] array, int low, int high) {
if (low < high) {
int p = partition(array, low, high);
qsort(array, low, p);
qsort(array, p+1, high);
}
}
如果您希望将onclick代码保持简单 REPLACE :
<button class="nm-simple-add-to-cart-button single_add_to_cart_button button alt" data-dismiss="modal" aria-label="Close" onclick="fillFields('coupon_code')" alutocomplete="off" id="gencode">Generate a Code</button>
你应该得到类似的结果:document.getElementById('coupon_code').value = 'THECOUPONCODE';