我目前正在使用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