Home Web Front-end JS Tutorial jQuery's value acquisition and assignment operation code for form elements_jquery

jQuery's value acquisition and assignment operation code for form elements_jquery

May 16, 2016 pm 06:06 PM
value Assignment

$("#keyword")[0].value = "";


/*Get the value of TEXT.AREATEXT*/
var textval = $("#text_id").attr ("value");
//or
var textval = $("#text_id").val();

/*Get the value of the radio button*/
var valradio = $("input[type=radio]:checked").val();

/*Get the values ​​of a group of radio selected items named (items)*/
var item = $('input[name=items]:checked').val();

/*Get the value of the checkbox*/
var checkboxval = $("#checkbox_id").attr ("value");

/*Get the value of the drop-down list*/
var selectval = $('#select_id').val();

/*Text box, Text area*/
$("#text_id").attr("value",");//Clear the content
$("#text_id").attr("value",'test'); //Fill content

/*Multiple selection box checkbox*/
$("#chk_id").attr("checked",");//Make it unchecked
$( "#chk_id").attr("checked",true);//Check
if($("#chk_id").attr('checked')==true) //Determine whether it has been selected

/*Single selection group radio*/
$("input[type=radio]").attr("checked",'2');//Set the item with value=2 as the currently selected item

/*Drop-down box select*/
$("#select_id").attr("value",'test');//Set the item with value=test as the currently selected item
$("testtest2").appendTo("#select_id")//Add the option of the drop-down box
$("#select_id").empty();//Clear the drop-down box

/*Get The value of a group of radio selected items named (items)*/
var item = $('input[name=items]:checked').val(); //If not selected, val() = undefined

/*Get the text of the selected item*/
var item = $("select[name=items] option:selected").text();

/*The second element of the select drop-down box is the currently selected value*/
$('#select_id')[0].selectedIndex = 1;

/*The second element of the radio radio selection group The element is the currently selected value*/
$('input[name=items]').get(1).checked = true;

/*Reset the form*/
$(" form").each(function(){
.reset();
});
jQuery takes and assigns values ​​to html elements

Jquery gives basic Control value acquisition and assignment TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //Text box, text area: $( "#text_id").attr("value",'');//Clear the content$("#text_id").attr("value",'test');//Fill the content
Jquery to basic controls Value acquisition and assignment

TEXTBOX:
var str = $('#txt').val();

$('#txt').val("Set Lbl Value");

//Text box, text area:
$("#text_id").attr("value",'');//Clear the content
$("# text_id").attr("value",'test'); // Fill content
LABLE:

var str = $('#lbl').text();

$('#lbl').text("Set Lbl Value");

var valradio = $("input[@type=radio][@checked]").val();
var item = $('input[@name=items][@checked]').val();
var checkboxval = $("#checkbox_id").attr("value");
var selectval = $('#select_id').val();
//Multiple selection box checkbox:
$("#chk_id").attr("checked",'');//Make it unchecked Check
$("#chk_id").attr("checked",true);// Check
if($("#chk_id").attr('checked')==true) / /Determine whether the
radio group radio has been selected:

$("input[@type=radio]").attr("checked",'2'); //Set value=2 The item is the currently selected item

//Drop-down box select:
$("#select_id").attr("value",'test');//Set the item with value=test as the currently selected item Item
$("").appendTo("#select_id")//Add the option of the drop-down box
$("#select_id").empty (); //Clear the drop-down box

Get the value of a set of radio selected items named (items)
var item = $('input[@name=items][@checked]' ).val();//If not selected, val() = undefined
Get the text of the selected item
var item = $("select[@name=items] option[@selected]" ).text();
The second element of the select drop-down box is the currently selected value
$('#select_id')[0].selectedIndex = 1;
The second element of the radio radio selection group The element is the currently selected value
$('input[@name=items]').get(1).checked = true;

//Reset the form
$("form") .each(function(){
.reset();
}; //Text box, text area: $("#text_id").attr("value",'');//Clear the content $("#text_id").attr("value",'test');/ / Fill content
Jquery’s value collection and assignment to basic controls

TEXTBOX:
var str = $('#txt').val();

$(' #txt').val("Set Lbl Value");

//Text box, text area:
$("#text_id").attr("value",'');/ /Clear content
$("#text_id").attr("value",'test');// Fill content
LABLE:

var str = $('#lbl') .text();

$('#lbl').text("Set Lbl Value");

var valradio = $("input[@type=radio][@checked ]").val();
var item = $('input[@name=items][@checked]').val();
var checkboxval = $("#checkbox_id").attr ("value");
var selectval = $('#select_id').val();
//Multiple selection box checkbox:
$("#chk_id").attr("checked" ,'');//Make it unchecked
$("#chk_id").attr("checked",true);// Make it checked
if($("#chk_id").attr ('checked')==true) //Determine whether the
radio group radio has been selected:

$("input[@type=radio]").attr("checked",'2 '); //Set the item with value=2 as the currently selected item

//Drop-down box select:
$("#select_id").attr("value",'test');/ / Set the item with value=test as the currently selected item
$("
testtest2$("#select_id").empty();//Clear the drop-down box

Get the values ​​of a set of radio selected items named (items)
var item = $('input[ @name=items][@checked]').val();//If not selected, val() = undefined
Get the text of the selected item in select
var item = $("select[@ name=items] option[@selected]").text();
The second element of the select drop-down box is the currently selected value
$('#select_id')[0].selectedIndex = 1;
The second element of the radio radio selection group is the currently selected value
$('input[@name=items]').get(1).checked = true;

//Reset Form
$("form").each(function(){
.reset();
});

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to enable copy and paste for VMware virtual machines How to enable copy and paste for VMware virtual machines Feb 21, 2024 am 10:09 AM

You can easily copy and paste text and files between VMware virtual machines (VMs) and physical systems. This capability allows you to easily transfer images, formatted and unformatted text, and even email attachments between virtual machines and host systems. This article will show you how to enable this feature and demonstrate methods for copying data, files, and folders. How to Enable Copy/Paste in VMware VMware provides three different ways to copy data, files or folders from a virtual machine to a physical computer and vice versa, as explained below: Copy and Paste Elements Drag and Drop Feature Folder Sharing 1 ] Enable copy-paste using VMware Tools You can use the keyboard if your VMWare installation and guest operating system meet the requirements

How to copy a page in Word How to copy a page in Word Feb 20, 2024 am 10:09 AM

Want to copy a page in Microsoft Word and keep the formatting intact? This is a smart idea because duplicating pages in Word can be a useful time-saving technique when you want to create multiple copies of a specific document layout or format. This guide will walk you through the step-by-step process of copying pages in Word, whether you are creating a template or copying a specific page in a document. These simple instructions are designed to help you easily recreate your page without having to start from scratch. Why copy pages in Microsoft Word? There are several reasons why copying pages in Word is very beneficial: When you have a document with a specific layout or format that you want to copy. Unlike recreating the entire page from scratch

Disable or enable automatic copy selection for copying in Terminal Disable or enable automatic copy selection for copying in Terminal Mar 24, 2024 am 09:46 AM

This article will show you how to enable or disable automatic copying of selections to the clipboard in Windows Terminal. Windows Terminal is a multi-tab terminal emulator developed by Microsoft specifically for Windows 11/10, replacing the traditional command prompt. It supports running applications such as Command Prompt, PowerShell, WSL, Azure, etc. Often when working in the terminal, users need to copy commands and output, however the terminal does not support copying selection operations by default. Keep reading this article to learn how to fix this issue. How to enable or disable automatic copying of selections to cache in Terminal? Here's how you can enable or disable automatic copying of selections to the Terminal clipboard: Open the Terminal application and click above

Unlock macOS clipboard history, efficient copy and paste techniques Unlock macOS clipboard history, efficient copy and paste techniques Feb 19, 2024 pm 01:18 PM

On Mac, it's common to need to copy and paste content between different documents. The macOS clipboard only retains the last copied item, which limits our work efficiency. Fortunately, there are some third-party applications that can help us view and manage our clipboard history easily. How to View Clipboard Contents in Finder There is a built-in clipboard viewer in Finder, allowing you to view the contents of the current clipboard at any time to avoid pasting errors. The operation is very simple: open the Finder, click the Edit menu, and then select Show Clipboard. Although the function of viewing the contents of the clipboard in the Finder is small, there are a few points to note: the clipboard viewer in the Finder can only display the contents and cannot edit them. If you copied

What are the assignment methods in php? What are the assignment methods in php? Jul 26, 2023 pm 01:11 PM

The assignment methods in PHP include: 1. Direct assignment, use the "=" operator to directly assign a value to a variable; 2. Reference assignment, use the "=&" operator to assign a reference to a variable to another variable; 3. Dynamic assignment , using variable variables to assign values ​​through the string form of variable names; 4. Array assignment, assigning an array to another variable; 5. List assignment, assigning the value of an array to a set of variables, and multiple assignments can be made at one time value; 6. Object assignment, assign an object to a variable; 7. Use the extended form of the assignment operator, such as +=, -=, etc.

Tips and Notes: Different String Array Assignment Methods Tips and Notes: Different String Array Assignment Methods Dec 26, 2023 am 11:30 AM

Introduction to tips and precautions for using different ways to assign values ​​to string arrays: In programming, it is often necessary to use arrays to store a set of related data. Especially when dealing with strings, it is often necessary to use string arrays to store multiple strings. This article will introduce some common methods, tips and precautions for assigning values ​​to string arrays, and provide code examples. Direct assignment Direct assignment is the simplest way. You can directly assign values ​​to the array elements while declaring the string array. The sample code is as follows: String[]fruit

Learn variable definition and assignment in Golang Learn variable definition and assignment in Golang Jan 18, 2024 am 10:00 AM

The definition and assignment of variables in Golang require specific code examples. In Golang, the definition and assignment of variables are very simple and intuitive. This article will introduce the definition and assignment of variables in Golang through specific code examples. First, let's take a look at the definition of variables in Golang. In Golang, the definition of variables can be done using the var keyword. The specific syntax is as follows: var variable name type. Among them, var represents the definition keyword of the variable, and the variable name is the variable you define.

What are the methods of assigning values ​​to string arrays? What are the methods of assigning values ​​to string arrays? Dec 25, 2023 pm 05:07 PM

The assignment methods of string arrays in common programming languages: 1. Python: "string_array = ["apple", "banana", "cherry"]"; 2. Java: "String[] stringArray = {"apple", "banana" ", "cherry"}"; 3. C++ and so on.

See all articles