> 백엔드 개발 > PHP 튜토리얼 > jquery - 用php和ajax无刷新添加radio button并保存其选中的状态

jquery - 用php和ajax无刷新添加radio button并保存其选中的状态

WBOY
풀어 주다: 2016-06-06 20:30:51
원래의
1023명이 탐색했습니다.

点击第一张图的add按钮,会生成一个新的表格,并会保存其选中的单选框状态,但是再点击的话因为生成的单选框name属性一样,选中的状态会被顶掉
$id = mysql_insert_id();
$head = "

"; $foot = "

";
if($formate=='standard 85x55mm'){
$result = "

Formate:
standard 85x55mm
";
}else{
$result = " Formate:standard 85x55mm
";
}
if($formate=='carte double 170x55mm'){
$result.="carte double 170x55mm";
}else{
$result.="carte double 170x55mm";
}
if($papier=='350g couche mat'){
<code>            $result.="<td>
<input name="papier" type="radio" value="350g couche mat" checked>350g couche mat<br>";
        }else{
            $result.="</td>
<td>
<input name="papier" type="radio" value="350g couche mat">350g couche mat<br>";
        }
        if($papier=='300g offset'){
            $result.="<input name="papier" type="radio" value="300g offset" checked>300g offset</td>";
        }else{
            $result.="<input name="papier" type="radio" value="300g offset">300g offset";

        }
        if($imprimer=='Recto seule'){
            $result.="<td>
<input name="imprimer" type="radio" value="Recto seule" checked>Recto seule<br>";
        }else{
            $result.="</td>
<td>
<input name="imprimer" type="radio" value="Recto seule">Recto seule<br>";
        }
        if($imprimer=='Recto et verso'){
            $result.="<input name="imprimer" value="Recto et verso" type="radio" checked>Recto et verso</td>";
        }else{
            $result.="<input name="imprimer" value="Recto et verso" type="radio">Recto et verso";
        }
        if($pelliculage=='Recto seule brillant'){
            $result.= "<td>
<input name="pelliculage" value="Recto seule brillant" type="radio" checked>Recto seule brillant<br>";
        }else{
            $result.= "</td>
<td>
<input name="pelliculage" value="Recto seule brillant" type="radio">Recto seule brillant<br>";
        }
        if($pelliculage=='Recto seule mat'){
            $result.="<input name="pelliculage" value="Recto seule mat" type="radio" checked>Recto seule mat<br>";
        }else{
            $result.="<input name="pelliculage" value="Recto seule mat" type="radio">Recto seule mat<br>";
        }
        if($pelliculage=='Recto et verso brillant'){
            $result.="<input name="pelliculage" value="Recto et verso brillant" type="radio">Recto et verso brillant<br>";
        }else{
            $result.="<input name="pelliculage" value="Recto et verso brillant" type="radio">Recto et verso brillant<br>";
        }
        if($pelliculage=='Recto et verso mat'){
            $result.="<input name="pelliculage" value="Recto et verso mat" type="radio" checked>Recto et verso mat<br>";
        }
        else{
            $result.="<input name="pelliculage" value="Recto et verso mat" type="radio">Recto et verso mat<br>";
        }
        $result.="<table>
<thead>
<th>Id</th>
<th>count</th>
<th>price</th>
<th>price2</th>
<th>price3</th>
</thead>
<tbody>
<td>1</td>
<td><input name="count" type="text"></td>
<td><input type="text" name="price1"></td>
<td><input type="text" name="price2"></td>
<td><input type="text" name="price3"></td>
<td><button>add</button></td>
</tbody>
</table>";
        echo $head.$result.$foot;


<p><img  data-src="/img/bVmSW6" alt="jquery - 用php和ajax无刷新添加radio button并保存其选中的状态" ><br><img  data-src="/img/bVmSWG" alt="jquery - 用php和ajax无刷新添加radio button并保存其选中的状态" ></p>

<p><img  data-src="/img/bVmSWY" alt="jquery - 用php和ajax无刷新添加radio button并保存其选中的状态" ></p>
</td></code>
로그인 후 복사
로그인 후 복사

回复内容:

点击第一张图的add按钮,会生成一个新的表格,并会保存其选中的单选框状态,但是再点击的话因为生成的单选框name属性一样,选中的状态会被顶掉
$id = mysql_insert_id();
$head = "

"; $foot = "

";
if($formate=='standard 85x55mm'){
$result = "

Formate:
standard 85x55mm
";
}else{
$result = " Formate:standard 85x55mm
";
}
if($formate=='carte double 170x55mm'){
$result.="carte double 170x55mm";
}else{
$result.="carte double 170x55mm";
}
if($papier=='350g couche mat'){
<code>            $result.="<td>
<input name="papier" type="radio" value="350g couche mat" checked>350g couche mat<br>";
        }else{
            $result.="</td>
<td>
<input name="papier" type="radio" value="350g couche mat">350g couche mat<br>";
        }
        if($papier=='300g offset'){
            $result.="<input name="papier" type="radio" value="300g offset" checked>300g offset</td>";
        }else{
            $result.="<input name="papier" type="radio" value="300g offset">300g offset";

        }
        if($imprimer=='Recto seule'){
            $result.="<td>
<input name="imprimer" type="radio" value="Recto seule" checked>Recto seule<br>";
        }else{
            $result.="</td>
<td>
<input name="imprimer" type="radio" value="Recto seule">Recto seule<br>";
        }
        if($imprimer=='Recto et verso'){
            $result.="<input name="imprimer" value="Recto et verso" type="radio" checked>Recto et verso</td>";
        }else{
            $result.="<input name="imprimer" value="Recto et verso" type="radio">Recto et verso";
        }
        if($pelliculage=='Recto seule brillant'){
            $result.= "<td>
<input name="pelliculage" value="Recto seule brillant" type="radio" checked>Recto seule brillant<br>";
        }else{
            $result.= "</td>
<td>
<input name="pelliculage" value="Recto seule brillant" type="radio">Recto seule brillant<br>";
        }
        if($pelliculage=='Recto seule mat'){
            $result.="<input name="pelliculage" value="Recto seule mat" type="radio" checked>Recto seule mat<br>";
        }else{
            $result.="<input name="pelliculage" value="Recto seule mat" type="radio">Recto seule mat<br>";
        }
        if($pelliculage=='Recto et verso brillant'){
            $result.="<input name="pelliculage" value="Recto et verso brillant" type="radio">Recto et verso brillant<br>";
        }else{
            $result.="<input name="pelliculage" value="Recto et verso brillant" type="radio">Recto et verso brillant<br>";
        }
        if($pelliculage=='Recto et verso mat'){
            $result.="<input name="pelliculage" value="Recto et verso mat" type="radio" checked>Recto et verso mat<br>";
        }
        else{
            $result.="<input name="pelliculage" value="Recto et verso mat" type="radio">Recto et verso mat<br>";
        }
        $result.="<table>
<thead>
<th>Id</th>
<th>count</th>
<th>price</th>
<th>price2</th>
<th>price3</th>
</thead>
<tbody>
<td>1</td>
<td><input name="count" type="text"></td>
<td><input type="text" name="price1"></td>
<td><input type="text" name="price2"></td>
<td><input type="text" name="price3"></td>
<td><button>add</button></td>
</tbody>
</table>";
        echo $head.$result.$foot;


<p><img  data-src="/img/bVmSW6" alt="jquery - 用php和ajax无刷新添加radio button并保存其选中的状态" ><br><img  data-src="/img/bVmSWG" alt="jquery - 用php和ajax无刷新添加radio button并保存其选中的状态" ></p>

<p><img  data-src="/img/bVmSWY" alt="jquery - 用php和ajax无刷新添加radio button并保存其选中的状态" ></p>
</td></code>
로그인 후 복사
로그인 후 복사

为啥不生成name不一样的?

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿