我试图通过以下方式获取输入类型文本的值:
$( document ).on( 'click', '.reset-to-default-img', function(e) {
alert($('#image').val());
});
当我点击按钮时,我收到了未定义的警报消息。我想得到价值。不知道为什么。这是我的HTML:
<p>
<!-- Set Default Custom Image -->
<label for="widget-gallery-posts-widget[__i__][image]"></label>
<input name="widget-gallery-posts-widget[__i__][image]" id="widget-gallery-posts-widget-__i__-image" class="widefat" type="text" size="36" value="" />
<button class="upload_image_button button button-primary" type="button">Upload Your Custom Default Image</button> <br /> <br />
<img src="http://localhost/Gallery-Posts-Widget/wp-content/plugins/gallery-posts-widget/views/images/default-thumbnail.jpg" id="custom-default-img" width="150" height="100" />
</p>
我想获得此输入的值:
<input name="<?php echo $this->get_field_name( 'image' ); ?>" id="<?php echo $this->get_field_id( 'image' ); ?>" class="widefat" type="text" size="36" value="<?php echo esc_attr( $image ); ?>" />
有什么想法吗?
答案 0 :(得分:1)
$( document ).on( 'click', '.reset-to-default-img', function(e) {
var image=$(this).closest('p').find('.widefat').val();
});
答案 1 :(得分:1)
从您的php方法中,您获得了身份flex-basis:0
而非table {
width: 200px;
border: 1px solid #000;
}
.flex {
display: flex;
/* flex-wrap: wrap; breaks the layout in Chrome, too */
}
.icon:before {
content: "✆";
}
.content {
flex-grow: 1;
flex-shrink: 0;
flex-basis: 0;
}
,因此请更改以下代码
<table>
<tr>
<td>
<div class="flex">
<span class="icon"></span>
<span class="content">Lorem Ipsum dolor sit amet Lorem Ipsum dolor and so on ...</span>
</div>
</td>
</tr>
</table>