用jQuery交换输入按钮

时间:2019-01-29 17:58:58

标签: jquery

当用户单击“编辑”按钮时,该按钮应更改为“保存”按钮,反之亦然。这两个按钮将具有不同的操作。同样,当我单击“编辑”按钮时,应启用输入(开始日期和结束日期)。当我单击“保存”按钮时,(开始日期和结束日期)应该再次被禁用。

.img-swap {
  cursor: pointer;
}

.noframe-container {
  margin-left: 300px;
  min-width: 800px;
}

.surface-list,
.adj-surface-list {
  color: #555;
}

.width-max,
.adj-max-width {
  width: 1200px;
  min-width: 1000px;
  padding-top: 35px !important;
  font-family: Open Sans, Arial, Helvetica, sans-serif;
  margin-left: 100px;
}

.adj-categorybvheader {
  padding-bottom: 5px !important;
}

.heading-orange,
.categorybvheader {
  line-height: 30px;
  /* padding-bottom: 20px; */
  text-align: left;
  display: block;
}

.categorybvheader {
  font-weight: 400 !important;
  color: #f27c34 !important;
  letter-spacing: -1px;
}

.section-positioning h3,
.welcome-orange,
.categorybvheader,
.title-gray-disc {
  font-size: 33px;
  background-color: transparent;
  font-family: 'Open Sans';
  font-weight: 300;
  width: auto;
  text-indent: 0px;
  color: #fff;
  text-align: center;
  margin-bottom: 20px;
}

img.img-middle {
  vertical-align: middle;
  margin-top: -4px;
}

.right,
.btnCart,
.fr {
  float: right;
}

.right {
  float: right;
}

img,
fieldset,
img,
abbr,
acronym {
  border: 0;
}

.errorMsg,
.errorMsgHeader {
  background: #FEE9E8;
  border: 1px solid #FD8A85;
  color: #FF0103;
}

.infoMsg,
.errorMsg,
.errorMsgHeader {
  box-shadow: 0 1px 0 #FFFFFF inset;
  font-size: 14px;
  font-weight: bold;
  display: none;
  margin: 0 0 10px;
  padding: 5px;
  text-align: center;
}

.surface-list p,
.adj-surface-list p {
  padding: 10px 0 10px;
  line-height: 25px;
}

input,
textarea,
keygen,
select,
button {
  font-family: Arial, Helvetica, sans-serif;
}

.z-con-welcome {
  padding-right: 20px;
  line-height: 21px;
  color: #555555;
  margin-left: 200px;
  margin-bottom: 50px;
  margin-top: 30px;
}

.nomargTop {
  margin-top: 0!important;
}

.nomargLeftRight {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.left {
  float: left;
}

.form-box {
  width: 310px;
}

label.label-name {
  font-weight: bold;
  font-size: 14px;
  padding: 0 0;
  margin: 0;
  width: 100%;
}

label {
  float: left;
  width: 169px;
  font-size: 12px;
  margin: 0 0 10px 0;
}

.orange {
  color: #f27c34;
}

.adj-z-con-input {
  padding: 4px 0 4px 5px;
  margin: 5px 0 5px;
}

.z-con-input {
  font-size: 16px;
  color: #555555;
  border: 2px solid #e6e6e6;
  width: 250px;
  border-radius: 5px;
  padding: 5px 0 5px 10px;
  float: left;
}

.clear {
  clear: both;
  visibility: visible;
}

.margToptwen,
.leftboxTopMargin {
  margin-top: 20px!important;
}

.adj-quote-search-box {
  width: 863px !important;
  overflow: hidden;
}

.quote-search-box {
  background: #f3f3f3;
  width: 550px;
  padding: 20px;
  line-height: 25px;
  margin-bottom: 10px;
}

.norigtPad {
  padding-right: 0 !important;
}

.z-con-welcome {
  padding-right: 20px;
  line-height: 21px;
  color: #555555;
  margin-left: 200px;
  margin-bottom: 50px;
  margin-top: 30px;
}

.nomargTop {
  margin-top: 0!important;
}

.nomargLeftRight {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.bottomMarg {
  margin-bottom: 20px !important;
}

.orange {
  color: #f27c34;
}

.plzCall {
  font-size: 20px !important;
}

.sku-width-lab {
  width: 166px !important;
}

.qty-width,
.sku-width {
  margin-right: 30px;
}

.sku-width {
  width: 176px;
}

.width76 {
  width: 76px !important;
}

.adj-label-name {
  width: 400px !important;
  margin: 10px 0 !important;
}

.radio-space {
  margin-left: 10px !important;
  margin-right: 5px;
}

.radio-text {
  font-weight: normal;
  margin: 0 17px 0 0;
  color: #000;
}

.width-requst {
  margin-top: 30px;
}

.reason-label {
  width: 325px;
  height: 90px;
}

.norigtPad {
  padding-right: 0 !important;
}

.z-con-submit {
  color: #fff;
  letter-spacing: -1px;
  line-height: 24px;
  font-size: 18px;
  font-weight: bold;
  background-color: #f27c34;
  box-shadow: 0px 1px 2px #ccc;
  padding: 6px 24px;
  border-radius: 5px;
  margin-top: 50px;
  display: inline-block;
  cursor: pointer;
  transition: background-color .25s ease-in-out;
  -moz-transition: background-color .25s ease-in-out;
  -webkit-transition: background-color .25s ease-in-out;
}

.adj-categorybvheader {
  padding-bottom: 5px !important;
}

.heading-orange,
.categorybvheader {
  line-height: 30px;
  /* padding-bottom: 20px; */
  text-align: left;
  display: block;
}

.categorybvheader {
  font-weight: 400 !important;
  color: #f27c34 !important;
  letter-spacing: -1px;
}

.section-positioning h3,
.welcome-orange,
.categorybvheader,
.title-gray-disc {
  font-size: 33px;
  background-color: transparent;
  font-family: 'Open Sans';
  font-weight: 300;
  width: auto;
  text-indent: 0px;
  color: #fff;
  text-align: center;
  margin-bottom: 20px;
}

#selectDrop,
.selectDrop .shippingBox select,
#lst_ship_to_top {
  color: #1C3A54;
  font-size: 12px;
  padding: 3px;
  border: 1px solid #CCCCCC;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  background-color: #E8E8E8;
}

.select205 {
  width: 205px;
}

select {
  -moz-appearance: menulist;
}

.marg-right {
  margin-right: 30px;
}

.z-con-edit {
  color: #fff;
  /* letter-spacing: -1px; */
  line-height: 24px;
  font-size: 12px;
  font-weight: normal;
  background-color: #f27c34;
  box-shadow: 0px 1px 2px #ccc;
  padding: 0px 18px;
  border-radius: 3px;
  display: inline-block;
  cursor: pointer;
  transition: background-color .25s ease-in-out;
  -moz-transition: background-color .25s ease-in-out;
  -webkit-transition: background-color .25s ease-in-out;
}

.z-con-delete {
  color: #fff;
  /* letter-spacing: -1px; */
  line-height: 24px;
  font-size: 12px;
  font-weight: normal;
  background-color: #f27c34;
  box-shadow: 0px 1px 2px #ccc;
  padding: 0px 18px;
  border-radius: 3px;
  display: inline-block;
  cursor: pointer;
  transition: background-color .25s ease-in-out;
  -moz-transition: background-color .25s ease-in-out;
  -webkit-transition: background-color .25s ease-in-out;
}

div span {
  font-weight: bold;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="standards-page width-max surface-list">





  <form name=test action="#" method="post">

    <div class="z-con-welcome nomargLeftRight nomargTop left">
      <div class="left form-box">
        <label class="label-name">Start Date:<span class="orange">*</span></label>

        <input type="date" maxlength="50" name="company_name" field="start_date" value="" class="z-con-input adj-z-con-input" />
      </div>
      <div class="left form-box">
        <label class="label-name">End Date:<span class="orange">*</span></label>

        <input type="date" maxlength="50" name="end_date" field="end_date" value="" class="z-con-input adj-z-con-input" />
      </div>
      <div class="clear"></div>

      <div style="overflow-y:auto; height:100px; margin-top:40px;">

        <span style="margin-left:60px; margin-right:130px;">Name</span><span style="margin-right:180px;">Alias</span><span style="width:150px;">Email</span>

        <div class="margToptwen">
          <div class="left marg-right">
            <input type="radio" name="radio_opened_1" value="Un-Opened" $field{1_Un-Opened_checked} class="radio-space" />
          </div>
          <div class="left marg-right" style="width:150px">
            <label class="label-name">Sukhpreet</label>
          </div>
          <div class="left marg-right" style="width:180px">
            <label class="label-name">Alang</label>
          </div>
          <div class="left marg-right">
            <label class="label-name">sukhpreet.alang@zones.com</label>
          </div>
        </div>

        <div class="clear"></div>


      </div>
      <span style="text-align:right;">
    <input type="submit" value="Submit &raquo;" class="z-con-submit margToptwen" />
    </span>
    </div>
    <!--z-con-welcome-->

    <div class="clear"></div>


    <div style="overflow-y:auto; height:100px; margin-top:40px;">


      <span style="margin-right:130px;">Name</span><span style="margin-right:100px;">Alias</span><span style="margin-right:180px;">Email</span><span style="margin-right:80px;">Start Date</span><span style="margin-right:80px;">End Date</span>
      <div class="margToptwen">

        <div class="left marg-right" style="width:150px">
          <label class="label-name">Sukhpreet</label>
        </div>
        <div class="left marg-right" style="width:100px">
          <label class="label-name">Alang</label>
        </div>
        <div class="left marg-right" style="width:200px">
          <label class="label-name">sukhpreet.alang@zones.com</label>
        </div>
        <div class="left marg-right" style="width:130px">
          <input type="date" disabled/>
        </div>
        <div class="left marg-right" style="width:130px">
          <input type="date" disabled/>
        </div>
        <div class="left marg-right">
          <input type="button" class="z-con-edit" value="Edit" />
          <input type="button" class="z-con-delete" value="Save" />

        </div>
        <div class="left marg-right">
          <input type="button" value="Delete" class="z-con-delete" />
        </div>

      </div>


  </form>
  </div>

1 个答案:

答案 0 :(得分:0)

尝试一下。 在onclickedit按钮上分别添加save并使用不同的参数调用相同的方法toggleFunc(),如下所示:

toggleFunc = function(value) {
  if (value == 'save') {
    $('#IdOfEditButton').hide();
    $('#IdOfSaveButton').show();
    $('#IdOfStartDate').attr('disabled');
    $('#IdOfEndDate').attr('disabled');
  } else {
    $('#IdOfSaveButton').hide();
    $('#IdOfEditButton').show();
    $('#IdOfStartDate').removeAttr('disabled');
    $('#IdOfEndDate').removeAttr('disabled');
  }
}

使用

<input type="button" value="save" onclick="toggleFunc('save')" />
<input type="button" value="edit" onclick="toggleFunc('edit')" />