我目前正在使用WooCommerce功能在WordPress網站上工作。爲了讓我的character_count正常工作,我需要對HTML和JavaScript代碼進行哪些更改?
我的一項任務是在產品頁面上插入一個自定義文本字段,購物者可以在其中指定一段文字,他們希望在他們的產品上看到。爲了加速這個過程,我使用了一個插件。產生這種自定義字段,插件輸出的產品頁面下面的代碼:
HTML:
<div class="fields-group-1">
<table class="fields_table product-custom-text-wrapper" cellspacing="0">
<tbody>
<tr>
<td class="label"><label class=" product-custom-text-label" for="custom_text">Custom Text</label></td>
<td class="value">
<input type="text" class="field product-custom-text" name="custom_text" value="" placeholder="Enter Custom Text ..." maxlength="16" type="text" pattern="mandatory" mandatory="no" />
<span class="validation-message is-valid-1"></span>
</td>
</tr>
</tbody>
</table>
</div>
我現在要輸出的字符數到產品頁面。瀏覽網後,我可以看到下面的代碼將在這方面幫助:
的JavaScript
$('textarea').keyup(updateCount);
$('textarea').keydown(updateCount);
function updateCount() {
var cs = $(this).val().length;
$('#character_count').text(cs);
}
目前,該代碼不起作用。使用上面的HTML,是否有人知道我需要將JavaScript代碼中的'textarea'更改爲,以便此代碼正常工作?
一旦我得到了代碼工作,我可以簡單地輸入<span id="character_count"></span>
代碼完成。
「input .product-custom-text」 –
您的HTML不包含'textarea'或'#character_count'? –
謝謝@Jonas w。 @AP ...當我使用插件時,它不會生成'textarea'標籤。至於'character_count' ID,這是在標籤內,我將在修復上述代碼後插入。感謝您的投入。 – Craig