如何检索输入类型编号的文本值?
我可以在有效数字
时检索该值1.23 //returns 1.23
1 //returns 1
但是当最后一个角色出现时,'。我似乎无法得到它。
2. //returns 2
希望它返回2.
HTML:
<input type="number" id="size" step="0.001"></td>
JS:
$("#size").val();
答案 0 :(得分:1)
使用type="number"
,您可能会获得输入值的编号版本。
如果您在Javascript中尝试Number('13.')
,则会获得13
将其更改为type="text"
,您应该获得整个价值。
答案 1 :(得分:0)
使用它:
parseFloat('1.23') // return 1.23;
parseFloat('1') // return 1;
parseFloat('2.') // return 2;
所有结果:
header('Content-Type: application/json');
$feed_url = 'http://localhost/json/j_xml.xml';
$xml_data = simplexml_load_file($feed_url);
// --------------------------------------------------------------------
$i=0;
$response = array('return' => true,'message' => 'success','details' => array() );
foreach($xml_data->channel->item as $ritem) {
$e_wp = $ritem->children("wp", true);
$e_author = $ritem->children("dc", true);
$e_content = $ritem->children("content", true);
// --------------------------------------
if((string)$e_wp->status =='publish') {
$post_id = (string)$ritem->guid;
$post_id = explode('=', $post_id);
$content['article_post_id'] = $post_id[1];
$content['article_title'] = (string)$ritem->title;
$content['article_cat_slug'] = 'News'.$post_id[1];
$content['article_mob_title'] = (string)$ritem->title;
$content['article_category'] = (string)$ritem->category;
$content['article_pub_date'] = (string)$e_wp->post_date;
$content['article_description'] = (string)$ritem->description;
$content['article_content'] = (string)$e_content->encoded;
$content['article_author'] = (string)$e_author->creator;
$content['article_seo_desc'] = '';
$content['article_seo_tags'] = '';
$content['article_fb_title'] = '';
$content['article_fb_desc'] = '';
$content['article_twitter'] = '';
$content['article_create_date'] = (string)$e_wp->post_date_gmt;
$content['article_status'] = (string)$e_wp->status;
}
array_push($response['details'],$content);
}
echo json_encode($response,JSON_PRETTY_PRINT);
答案 2 :(得分:0)
检查&#39;。&#39;使用字符串函数。如果它不存在,则追加它。 否则你必须使用输入类型文本。