2014-11-08 2 views
1

PHP 확장명으로 저장된 html 페이지가 있습니다. 여기에는 home_page_text와 aff_page_text의 두 필드가있는 입력 양식이 들어 있습니다. 또한 두 개의 버튼이 있습니다.버튼을 누를 때 양식 필드가 설정됩니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
</head> 
<body bgcolor="#EEE8AA"> 
    <form name="Form1" id="Form1" action="post_message.php" method="post"> 
    <input type="text" size="80" maxlength="400" 
    name="home_page_text" id="home_page_text" 
    value="" style="background-color:#EFD381" /> 

    <input type="text" size="80" maxlength="400" 
    name="aff_page_text" id="aff_page_text" 
    value="" style="background-color:#EFD381" /> 

    <input class="stand_alone_button_left_12em" type="button" value="Default The Message" 
    name="default_home" 
    onclick="return OnButton1();" /> 

    <input class="stand_alone_button_left_12em" type="button" value="Default The Message" 
    name="default_aff" 
    onclick="return OnButton2();" /> 

해당 버튼을 누를 때마다 두 개의 필드를 각각 다른 기본값으로 설정하고 싶습니다.

그래서 버튼 default_home을 누를 경우 I 필드 home_page_text 설정을하고 싶습니다에 "이것은 홈페이지 기본값입니다." 이에 따라 버튼을 눌렀을 경우 default_affaff_page_text을 "AFF PAGE 기본값"으로 설정하고 싶습니다.

값은 기본값으로 사용해야합니다. 사용자는 그대로 텍스트를 수락하거나 기본 텍스트를 편집 할 수 있습니다. 세 번째 버튼 (type = submit)을 누르면 페이지가 제출되어 게시물이 "post_message.php"와 같은 페이지를 호출하게됩니다.

어떻게하면됩니까?

답변

0

이 프로젝트에 jQuery 라이브러리가 설치되어 있습니까? jQuery로 작성하는 것이 훨씬 쉽습니다. 그렇지 않으면 일반 JavaScript를 사용해야합니다.

default_home 버튼을 누르면 jQuery는 home_page_text를 원하는대로 설정하고 다른 버튼을 누르면 동일한 작업을 수행합니다.

그렇지 않으면 Ajax 또는 PHP로이를 수행 할 수 있습니다. PHP를 사용하면 다른 버튼을 누를 때마다 전체 페이지 새로 고침이 필요합니다. (jQuery를 가장 효율적이다)

+0

나는 '수 jquery.cycle.all.js를 사용했습니다. 나는이 방법이라고 불렀다 : user3138025

+0

방금 ​​HostGator (호스팅 서버)를 확인하고 jquery를 지원한다는 것을 알고 있습니다. 도와 줘서 고마워. – user3138025

0

이뿐만 아니라 심지어 일반 자바 스크립트 달성 할 수 PHP, jQuery를, 또는 아약스 :

날 당신이이 문제를 해결하는 방법을 알려주십시오. default_home 버튼을 누르면, OnButton1이라는() 메서드에서 당신은 OnButton2에서 같은 방식으로,

document.getElementById("home_page_textotc").value = "This is the HOME PAGE default value"; 

를 아래와 같이 입력 값을 수정할 수() 메소드

document.getElementById("aff_page_textThis is the AFF PAGE default value").value = "This is the HOME PAGE default value"; 
관련 문제