jquery从对象获取元素

编程入门 行业动态 更新时间:2024-10-11 17:29:46
jquery从对象获取元素 - intl-tel-input从国家数据获取拨号代码(jquery get elements from object - intl-tel-input get dial code from country data)

我是jquery的新手,我试图在提交表单后从intl-tel-input的SelectedCountryData对象中获取值。

从文档getSelectedCountryData返回下面的东西,我想从它得到值“93”:

{ name: "Afghanistan (‫افغانستان‬‎)", iso2: "af", dialCode: "93" }

我可以成功返回电话号码,但是当我使用以下命令时,将返回调用代码的[calling_code] => [object Object] :

$("form").submit(function() { $("#phone-full").val($("#phone").intlTelInput("getNumber")); //this works $("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData")); //this doesn't });

以下是表单输入字段:

<input type="tel" id="phone" value="<?php echo $phone_number ?>"> <input id="phone-full" type="hidden" name="phone_number"> <input id="calling_code" type="hidden" name="calling_code">

I am new to jquery and I'm trying to get the values from the SelectedCountryData object in intl-tel-input after form submission.

From the documentation getSelectedCountryData returns something like below and I want to get the value "93" from it:

{ name: "Afghanistan (‫افغانستان‬‎)", iso2: "af", dialCode: "93" }

I can successfully return the phone number but [calling_code] => [object Object] is returned for the calling code when I use the following:

$("form").submit(function() { $("#phone-full").val($("#phone").intlTelInput("getNumber")); //this works $("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData")); //this doesn't });

Here are the form input fields:

<input type="tel" id="phone" value="<?php echo $phone_number ?>"> <input id="phone-full" type="hidden" name="phone_number"> <input id="calling_code" type="hidden" name="calling_code">

最满意答案

我设法解决这个问题,希望对其他人有用:

$("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData").dialCode);

I managed to solve this so in the hope that it is useful for someone else:

$("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData").dialCode);

更多推荐

本文发布于:2023-07-30 14:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338750.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   对象   jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!