我尝试在标题和说明框中添加占位符。
我已经尝试过这个脚本,但它无效!
希望有人能以正确的方式帮助我!
<script type="text/javascript">
$( document ).ready(function() {
$('#title').attr("placeholder", "test");
$('#description').attr("placeholder", "test");
});
</script>
<div id="item-post-title" class="item-post-title">
<label class="control-label" for="title[<?php echo osc_current_user_locale(); ?>]" style="width: auto;display: inline-block;">
<span class="required_fields">* </span>
<?php _e('Title', 'ctg_housing'); ?>
(<?php printf(__('max %s chars','ctg_housing'),$max_character_length_title); ?>)
</label> <span id="Tcounter"></span>
<?php ItemForm::title_input('title',osc_current_user_locale(), osc_esc_html( ctg_housing_item_title() )); ?>
</div>
<div id="item-post-description" class="item-post-description">
<label class="control-label" for="description[<?php echo osc_current_user_locale(); ?>]" style="width: auto;display: inline-block;">
<span class="required_fields">* </span>
<?php _e('Description', 'ctg_housing'); ?>
(<?php printf(__('max %s chars','ctg_housing'),$max_character_length_description); ?>)
</label> <span id="Dcounter"></span>
<?php ItemForm::description_textarea('description',osc_current_user_locale(), osc_esc_html( ctg_housing_item_description() )); ?>
<?php if(!osc_plugin_is_enabled('richedit/index.php')){ ?>
<?php } ?>
</div>
由于
答案 0 :(得分:0)
首先检查你的jquery libraby是否包含,如果没有,那么你可以通过
添加cdn jquery <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
或者您可以使用js设置placholder。(例如我在div下面添加)。
document.getElementById("title").placeholder = "hello";
注意:请在div或页脚下添加js。
示例 - 强>
<div id="item-post-title" class="item-post-title">
<label class="control-label" for="title[<?php echo osc_current_user_locale(); ?>]" style="width: auto;display: inline-block;">
<span class="required_fields">* </span>
<?php _e('Title', 'ctg_housing'); ?>
(<?php printf(__('max %s chars','ctg_housing'),$max_character_length_title); ?>)
</label> <span id="Tcounter"></span>
<?php ItemForm::title_input('title',osc_current_user_locale(), osc_esc_html( ctg_housing_item_title() )); ?>
</div>
<div id="item-post-description" class="item-post-description">
<label class="control-label" for="description[<?php echo osc_current_user_locale(); ?>]" style="width: auto;display: inline-block;">
<span class="required_fields">* </span>
<?php _e('Description', 'ctg_housing'); ?>
(<?php printf(__('max %s chars','ctg_housing'),$max_character_length_description); ?>)
</label> <span id="Dcounter"></span>
<?php ItemForm::description_textarea('description',osc_current_user_locale(), osc_esc_html( ctg_housing_item_description() )); ?>
<?php if(!osc_plugin_is_enabled('richedit/index.php')){ ?>
<?php } ?>
</div>
<script type="text/javascript">
document.getElementById("title").placeholder = "hello";
</script>
请检查这个jsfiddle http://jsfiddle.net/889zepgf/
答案 1 :(得分:0)
据我了解您的代码,它会动态生成字段ID - titleen_US
,descriptionen_US
等。因此您无法访问它 - jQuery中的$('#title').attr("placeholder", "test");
和$('#description').attr("placeholder", "test");
。
这样做不是更好的解决方案 -
$( document ).ready(function() {
$('#titleen_US').attr("placeholder", "test");
$('#descriptionen_US').attr("placeholder", "test");
});
因为,您的 osc_current_user_locale()
将根据用户区域设置返回不同的值,仅适用于区域设置 - en_US 和不适用于其他语言环境。
因此,将 类 属性应用于您的html输入而不是使事情复杂化 -
class="title"
&amp;分别为class="description"
,因此您的jQuery代码将为 -
$( document ).ready(function() {
$('.title').attr("placeholder", "test");
$('.description').attr("placeholder", "test");
});
答案 2 :(得分:0)
感谢您的解决方案!
<script type="text/javascript">
$( document ).ready(function() {
$('#titleen_US').attr("placeholder", "Test Title");
});
</script>