如何在javascript中删除后面代码中创建的文本框?

时间:2016-08-11 10:20:48

标签: javascript c# jquery asp.net textbox

我在后面的代码中创建了一个文本框:

        HtmlGenericControl tdFromCounty = new HtmlGenericControl("td");

        TextBox tbFromCounty = new TextBox();
        tbFromCounty.CssClass = "rateinput";
        tbFromCounty.Style.Add("width", "200px");
        tbFromCounty.Text = "";
        tbFromCounty.ID = "fc" + this.ID.ToString();
        tbFromCounty.Attributes.Add("onblur", "UpdateCellFromCounty(" + this.ID + ",this.value)");
        tdFromCounty.Controls.Add(tbFromCounty);

在javascript中我正在检查以确保输入到文本框中的值是有效的县。如果它无效,那么我想删除文本框。

到目前为止,我已经尝试了这些,但没有一个可以工作:

$("#fc"+ result.Element).val == "";
$("#fc"+ result.Element).val = "";
$("#fc"+ result.Element).val("");

1 个答案:

答案 0 :(得分:-1)

试试这个:

 ## DefaultController.php ##
 /**
 *   @Route("/admini/articleadd", name="articleadd")
 */
 public function articleAdd(Request $request){
 $article = new Article();
 $form = $this->createFormBuilder($article)
    ->add('title', TextType::class, array('attr' => array('maxlenght' => 14)))
    ->add('text', TextareaType::class)
    ->add('image', FileType::class)
    ->add('add', SubmitType::class, array('label' => 'Create Article'))
    ->getForm();
 $form->handleRequest($request);
 if ($form->isSubmitted() && $form->isValid()) {
        $article = $form->getData();
        /** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
 $file = $article->getImage();
 $fileName = md5(uniqid());
 $file->move(
            $this->getParameter('image_directory'),
            $fileName
        );
 $article->setImage($fileName);
 $em = $this->getDoctrine()->getManager();
 $em->persist($article);
 $em->flush();
 return $this->redirectToRoute('login');
}
return $this->render('default/articleadd.html.twig', array(
        'form' => $form->createView(),
        ));
}

 #Article.php

 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;

 /**
 * @ORM\Entity
 * @ORM\Table(name="Article")
 */
 class Article
 {   //...// 
     /**
     * @ORM\Column(type="string")
     * @Assert\File(mimeTypes={ "image/jpeg" })
     */
    private $image;
    //...//
 }

抱歉,应该是

$("#fc"+ result.Element).attr("value") = "";