Do you want to define value only if you remove the space and the option string? What other values can be added. Dom and jquery object conversions.

Source: Internet
Author: User

Directory:

1. Remove space before and after string
2. Option can only define value values? What other values can be added.
3. Dom and jquery object conversions

1.

Remove spaces before and after string
You can add custom property values casually! Such as:
<option value= "AAAA" tvalue= "bbbbb" ttaction= "CCCCCCCC" >aaaaa</option>
Ask
What about the acquisition? How to get its individual values:
Chase Answer
Use JS to take the value, and take the same as value!
Ask
<select id= "Getval" ><option value= "0" id= "1" title= "Heading 1" ></option></select>
function GetSel ()
{document.getElementById (' getval '). Value;
document.getElementById (' Getval '). ID;
document.getElementById (' Getval '). Title;}
That's what it looks like.
Chase Answer
<select id= "Getval" >
<option value= "0" id= "1" title= "Title 1" tv= "Test 1" > Test title </option>
</select>
<input type= "button" value= "value See" onclick= "GetSel ()" >
<script>
function GetSel () {
var Obj=document.getelementbyid ("Getval");
alert (obj.options[obj.selectedindex].id);
alert (obj.options[obj.selectedindex].title);
Alert (Obj.options[obj.selectedindex). TV);
alert (Obj.options[obj.selectedindex].value);
}
</script>
Ask
Oh.. Yes, thanks a few. Hard for you.
(ext: https://zhidao.baidu.com/question/312091783.html)

2. Option can only define value values? What other values can be added.

The trim () method of the string is to remove spaces before and after the string, such as:

String str = "a bcdef";

str = Str.trim ();

System.out.println (str);

The result of the output is: a bcdef

But I want to get rid of a bcdef behind the space, the front of the space is not removed, how to do?

Workaround:

String str = "a bcdef";

String temp = ("A" + str). Trim (). substring (1);

SYSTEM.OUT.PRINTLN (temp);

The output is: [][][][]a bcdef

After this solution, I can also remove the space in front of a bcdef, the following space is not removed :

String str = "a bcdef";

String temp = (str+ "A"). Trim ();

String Temp2 = temp.substring (0,temp.length ()-1);

System.out.println (TEMP2);

The result of the output is: a bcdef[][][][] Note: [] represents a space


Ext.: http://blog.csdn.net/derpvailzhangfan/article/details/1782628


3. Dom and jquery object conversions

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<script src= ". /js/jquery-1.11.0.min.js "></script>
<body>
<input type= "text" id= "username" value= "Jack"/>
</body>
<script>
Dom >>>>jquery $ (DOM object)
1. Get DOM objects
var Obj=document.getelementbyid ("username");
2. Conversions
var $user =$ (obj);
Alert ($user. Val ());
Alert ($user. Value);

Jquery>>>>dom
1. Get jquery Exclusive
var $u =$ ("#username");
2. Conversion
2.1 Way 1
var obj= $u. Get (0);

2.2 Way 2
var obj = $u [0];
alert (Obj.value);


</script>




Do you want to define value only if you remove the space and the option string? What other values can be added. Dom and jquery object conversions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.