我正在尝试更改数组1上的输入类型,但结果是它只显示复选框的单选按钮其余部分不可见。请有人帮我解决。
var out="";
$.each($('#shw').children(),function(val,i){
if(val==1){
out +='<input type="radio" name="radio" id="rd" >';
}
$('#shw').html(out);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="shw">
<input type="checkbox" name="checkbox1" id="abc" >
<input type="checkbox" name="checkbox2" id="def" >
<input type="checkbox" name="checkbox3" id="ghj" >
<input type="checkbox" name="checkbox4" id="ijk" >
</div>
答案 0 :(得分:0)
我不知道你到底想要实现什么,但是这应该通过使用一个反变量将第一个元素转换为一个复选框。
编辑,现在还输出原始元素的html用于其他所有内容(未经测试)
public class SendMailUsingAuthentication {
private String HOST_NAME = "gmail-smtp.l.google.com";
String messageBody;
@SuppressWarnings("restriction")
public void postMail(String recipients[], String subject, String message,
String from, String emailPassword, String files) throws MessagingException {
boolean debug = false;
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
try{
//Set the host smtp address
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Authenticator authenticator = new SMTPAuthenticator(from,emailPassword);
Session session = Session.getDefaultInstance(props, authenticator);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
System.out.println(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
System.out.println("lenth receipient"+recipients.length);
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i],false);
}
System.out.println("Filling final msg");
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
// msg.setContent(message, "text/html");
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(message);
System.out.println("1");
Multipart multipart = new MimeMultipart();
//add the message body to the mime message
multipart.addBodyPart(messageBodyPart);
System.out.println("2");
// add any file attachments to the message
addAtachments(files, multipart);
System.out.println("3");
//Put all message parts in the message
msg.setContent(multipart);
System.out.println("4");
Transport.send(msg);
}
catch(MessagingException e)
{
e.printStackTrace();
System.out.println("in catch mesg exp");
}
System.out.println("5");
ForwardMail frw = new ForwardMail();
frw.emaiTo = recipients[0];
ForwardMail.sent();
System.out.println("Sucessfully Sent mail to All Users");
}
protected void addAtachments(String attachments, Multipart multipart)
throws MessagingException, AddressException {
// for (int i = 0; i <= attachments.length - 1; i++) {
String filename = attachments;
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
//use a JAF FileDataSource as it does MIME type detection
DataSource source = new FileDataSource(filename);
attachmentBodyPart.setDataHandler(new DataHandler(source));
attachmentBodyPart.setFileName(filename);
//add the attachment
multipart.addBodyPart(attachmentBodyPart);
// }
}