我有2个这样的元素
<div class="div1">Slider</div>
<div class="div2">User Profile</div>
我希望这个元素结构像这样(使用:jquery,javascript,css)
<div class="div2">User Profile</div>
<div class="div1">Slider</div>
答案 0 :(得分:3)
将insertBefore
与prev
选项一起使用。
$('.div2').insertBefore($('.div2').prev('.div1'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="div1">Slider</div>
<div class="div2">User Profile</div>
答案 1 :(得分:3)
您可以使用$(".div1").insertAfter($(".div2"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="div1">Slider</div>
<div class="div2">User Profile</div>
$(".div2").insertBefore($(".div1"));
或更早
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="div1">Slider</div>
<div class="div2">User Profile</div>
import csv
def category():
for line in csv_reader:
if line[1] == ("Male"):
line[1] = "0"
elif line[1] == ("Female"):
line[1] = "1"
csv_writer.writerow(line)
def pets():
for line in csv_reader:
if line[2] == ("Cat"):
line[2] = "0"
elif line[2] == ("Dog"):
line[2] = "1"
else: line[2] = "2"
csv_writer.writerow(line)
with open('information.csv', 'r', encoding = 'utf') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader)
with open('updated_version.csv', 'w', encoding ='utf-8', newline ='') as
new_file:
csv_writer = csv.writer(new_file)
for line in csv_reader:
category()
pets()
答案 2 :(得分:1)
使用.after()
或$("#div1").after($("#div2"));
:
$("#div2").before($("#div1"));
OR:
Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
cn.Open()
cmd = New SqlCommand("insert into CandTable(Passport_No,Name,Father
Name,Mother Name,Date_of_Birth) values('" & Candi.TxtPass.Text & "','" &
Candi.TxtName.Text & "', '" & Candi.TxtFather.Text & "', '" &
Candi.TxtMother.Text & "','" & Candi.TxtDob.Text & "')", cn)
cmd.ExecuteNonQuery()
cn.Close()
MsgBox("Data Saved Successfully")
End Sub
此方法将第一个元素放在第二个元素之前/之后,只要它们是相邻的兄弟姐妹。